﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Gqq.Csharpindepth.Chapter8910
{
    public class ExpressionClass
    {
        public static void ExpressionTest()
        {
            Func<int, bool> f = x => x < 6 && x > 4;
            Expression<Func<int, bool>> expf = x => x < 6 && x > 4;
            Console.WriteLine("Name:" + expf.Name);
            Console.WriteLine(expf.Body);
            Console.WriteLine(expf.CanReduce);
            Console.WriteLine(expf.NodeType);
            Console.WriteLine(expf.Compile()(3));
        }

        public static void ExpressionTest2()
        {
            var pe = Expression.Parameter(typeof (int), "n");
            var mult = Expression.Multiply(pe, pe);
            var exp = Expression.Lambda<Func<int, int>>(mult, pe);
            int result = exp.Compile()(2);
            Console.WriteLine(result);
        }

    }
}
